<?php require_once 'conf.php'; ?>
<?php include("includes/libs.php"); ?>
<?php

	 		$userid = 1;
	
	 		require_once "classes.php";
	 		require_once "services/budgetServices.php";
			$service = new CommonServices;
			$budgetServices = new BudgetService;
				 
			$con = mysql_connect(GlobalConfig::db_host_name,GlobalConfig::db_username,GlobalConfig::db_password);
			if (!$con)
			  {
			  die('Could not connect: ' . mysql_error());
			  }
			
			mysql_select_db(GlobalConfig::db_name, $con);
			
			$result = mysql_query("select * from account where userid = ". $userid);
			
			$equity = 0;
			
			while($row = mysql_fetch_array($result))
			{
				$balance =  $service->getBalanceForAcccount($row['id']);
				$equity = $equity + $balance;
			}
			
			$conn = new PDO(GlobalConfig::db_pdo_connect_string, GlobalConfig::db_username, GlobalConfig::db_password);
			$stmt = $conn->prepare("insert into equity_history value (NOW(), :amount)");
			$stmt->bindParam(':amount', $equity);
			$stmt->execute();
			echo "Equity = ".$equity;
?>